ScanDocument EmbedFont
To ensure accurate rendering of text during the marking process, it is necessary to embed the required fonts. By embedding the fonts, they become accessible during the marking process and can be utilized by ScanScript. It's important to note that the marking controller does not store any font files from the design computer. Therefore, embedding the font characters allows the controller to have access to the necessary fonts, ensuring consistent text rendering during marking.
Fonts are not allowed to embed if the keepScanShapes property was set to FALSE during ScanDocument creation. Call scanDocumentDataType to check if the Scandocument type is set to ScanDocumentDataType.ApiData.
Also, The fonts should be available in the application fonts folder, if not an file not found exception will be thrown.
Overloads
public void EmbedFont(string fontName, FontStyle fontStyle, IEnumerable<UnicodeRange> unicodeRanges) |
public void EmbedFont(string fontName, int fontStyle, UnicodeRange unicodeRanges) |
Return value
void |
Parameters
string | fontName | Name of the font to embed |
FontStyle | fontStyle | The font style to use Ex:bold, italic, etc.. |
UnicodeRange | unicodeRanges | Unicode range of the font to be embedded |
Exceptions
InvalidOperationException | Throws if the Scandocument type is not set to ScanDocumentDataType.ApiData |
FileNotFoundException | Throws if the font is not located inside the Application fonts folder |
Example
scanDocument = scanDeviceManager.CreateScanDocument(GetselectedDeviceUniqueName(), DistanceUnit.Millimeters, false);
scanDocument.SetScanDocumentName("SerialNumberSample");
// Create a serial number variable
SerialNumber serialVar = new SerialNumber("SerialID");
// Add new line
serialVar.SerialItemList.Add(new NewLineSerialItem());
// Add static text part of the serial number
TextSerialItem textPart = new TextSerialItem();
textPart.Text = "Serial # : ";
serialVar.SerialItemList.Add(textPart);
// Add the number serial item part
NumberSerialItem numberSerialItem = new NumberSerialItem();
numberSerialItem.IsCurrentNumberEnabled = true;
numberSerialItem.StartNumber = 1;
numberSerialItem.CurrentNumber = 1;
numberSerialItem.EndNumber = 100;
numberSerialItem.Increment = 1;
numberSerialItem.FixedLength = 3;
numberSerialItem.RepeatCount = 0;
numberSerialItem.NumarelRepresentation = NumberSystemStyle.Decimal;
serialVar.SerialItemList.Add(numberSerialItem);
serialVar.SerialItemList.Add(new NewLineSerialItem());
//Save a job to SMC
scanDocument.IsSaveAndUseSerailizationState = true;
//Loop cycles
scanDocument.SetIterations(100);
//Add serialNumber to ScanDocument
scanDocument.AddSerialNumberVariable(serialVar);
//Day to expire
scanDocument.SerailizationStateSaveDataExpirationTime = 1;
if (scanDocument != null)
{
VectorImage vectorImage = scanDocument.CreateVectorImage("image1", DistanceUnit.Millimeters);
vectorImage.SetMarkSpeed(1000);
vectorImage.SetJumpSpeed(2000);
vectorImage.SetJumpDelay(100);
vectorImage.SetMarkDelay(100);
//Set Laser Delays
vectorImage.SetLaserOnDelay(10);
vectorImage.SetLaserOffDelay(10);
//Dynamic Text
DynamicTextShape dynamicText = new DynamicTextShape();
dynamicText.Height = 5;
dynamicText.Location = new Point3D(0, 0, 0);
dynamicText.VariableName = "dynText1";
dynamicText.Text = "Text1";
dynamicText.EvaluateVariableTags = true;
dynamicText.FontName = "Arial";
dynamicText.CharacterGap = 0;
dynamicText.ScaleX = 1;
dynamicText.ScaleY = 1;
dynamicText.Angle = 0;
// Characters from 0 to 255 or basically extended ASCII range is embedded
Collection<UnicodeRange> unicodeRanges = new Collection<UnicodeRange>();
UnicodeRange unicodeRange = new UnicodeRange();
unicodeRange.StartingCharacter = Convert.ToChar(0x00);
unicodeRange.EndingCharacter = Convert.ToChar(0xff);
unicodeRanges.Add(unicodeRange);
scanDocument.EmbedFont("Arial", FontStyle.Regular, unicodeRanges); // We need to embed the font for dynamic text shapes top be marked
vectorImage.AddDynamicText(dynamicText, new SerialNumberEx(serialVar));
scanDocument.Scripts.Add(new ScanningScriptChunk("defaultScript", "ScanAll()\r\nLaser.WaitForEnd()"));
try
{
scanDocument.StartScanning();
}
catch
{
}
}